home *** CD-ROM | disk | FTP | other *** search
- // BitReference.h
-
- #ifndef BitReference_h
- #define BitReference_h
-
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- class BitReference
- {
- private:
- uint32& unit;
- const uint32 mask;
-
- public:
- BitReference( uint32& theUnit, uint32 bitNumber )
- : unit( theUnit ),
- mask( 1ul << bitNumber )
- {
- Assert( bitNumber < 32 );
- }
-
- operator bool() const { return (unit & mask) != 0; }
-
- void operator=( bool b )
- {
- if ( b )
- Set();
- else
- Clear();
- }
-
-
- void Set() { unit |= mask; }
- void Clear() { unit &= ~mask; }
- void Change() { unit ^= mask; }
-
- void operator&=( bool b ) { if ( !b ) Clear(); }
- void operator|=( bool b ) { if ( b ) Set(); }
- void operator^=( bool b ) { if ( b ) Change(); }
- };
-
- #endif
-